import java.io.IOException;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.TiledLayer;


public class CanvasManager extends LayerManager {

	private TiledLayer background = null;
	private TiledLayer foreground = null;
	
	public CanvasManager(){
		Image backImage = null;
		Image foreImage = null;
		
		try {
			backImage = Image.createImage("/map/back.png");
			foreImage = Image.createImage("/map/fore.png");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		background = new TiledLayer(10, 8, backImage, 48, 64);
		background.fillCells(0, 0, 10, 8, 2);
		
		insert(background, 0);
		
		foreground = new TiledLayer(30, 32, foreImage, 16, 16);
		// 30 * 32
		int[][] mapdatas = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,24,0,0,24,0,0,0,0,0,0,0,0,13,14,15,16,17,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,19,20,46,22,23,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,1,2,3,4,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,7,8,9,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,37,38,39,0,18,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,43,44,45,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,1,2,3,4,5,0,0,0,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,7,8,9,10,11,0,0,0,0,0,0,18,0,0,0,6,0,6,6,0,6,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,27,0,0,27,27,0,27,0,0,27,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,27,0,0,0,0,0,0},
				{0,0,12,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
		
		for(int i=0;i<mapdatas.length;i++)
			for(int j=0;j<mapdatas.length;j++)
				foreground.setCell(j, i, mapdatas[i][j]);
		
		insert(foreground, 0);
	}
}
